package com.dynamic.model.util.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringBeanUtils
  implements ApplicationContextAware
{
  private static SpringBeanUtils instance = null;
  private static ApplicationContext applicationContext;

  public static SpringBeanUtils getInstance()
  {
    if (instance == null)
    {
      instance = new SpringBeanUtils();
    }
    return instance;
  }

  public void setApplicationContext(ApplicationContext arg0)
    throws BeansException
  {
    applicationContext = arg0;
  }

  public static ApplicationContext getApplicationContext()
  {
    return applicationContext;
  }

  public static Object getBean(String name) throws BeansException
  {
    return applicationContext.getBean(name);
  }

  public static <T> T getBean(String name, Class<T> requiredType)
    throws BeansException
  {
    return applicationContext.getBean(name, requiredType);
  }

  public static <T> T getBean(Class<T> requiredType)
    throws BeansException
  {
    return applicationContext.getBean(requiredType);
  }
}